﻿using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

namespace EICS_Automate_Test
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class UI_Login
    {
        public UI_Login()
        {
        }

        [TestMethod]
        public void CodedUILoginConnectionFail()
        {
            this.UIMap.InputUserName();
            this.UIMap.InputPassword();
            //this.UIMap.ClickLoginButton();
            this.UIMap.ErrorLoginConnectionMsgbox();
            this.UIMap.LoginErrorConnectionMsgboxClose();
            this.UIMap.ClickCancelLogin();

            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        }

        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestCase\\LoginTestCase.csv", "LoginTestCase#csv", DataAccessMethod.Sequential), DeploymentItem("EICS-Automate-Test\\TestCase\\LoginTestCase.csv"), TestMethod]
        //[TestMethod]
        public void CodedUILoginTestCaseData()
        {
            this.UIMap.InputUserName();
            this.UIMap.UILoginWindow.UIEICSEng01Window.UITxtUserIdEdit.Text = TestContext.DataRow["UserID"].ToString();
            this.UIMap.UILoginWindow.UIEICSEng01Window3.UIPasswordEdit.Text = TestContext.DataRow["Password"].ToString();
            this.UIMap.ClickLoginButton();
            if (TestContext.DataRow["Login"].ToString().Equals("Pass"))
            {
                this.UIMap.CheckDisplayLoginUserName();
                this.UIMap.CloseApplication();
            }
            else if (TestContext.DataRow["Login"].ToString().Equals("InfoInvalidUser"))
            {
                this.UIMap.ShowInfoInvalidUser();
                this.UIMap.CloseInfoInvalidUserId();
                this.UIMap.ClickCancelLogin();
            }
            else if (TestContext.DataRow["Login"].ToString().Equals("ValidateInvalidUser"))
            {
                this.UIMap.CheckShowInvalidUserID();
                this.UIMap.AssertInvalidUserID();
                this.UIMap.WarningInvalidUserIDMsgBoxClose();
                this.UIMap.ClickCancelLogin();
            }
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        }

        [TestMethod]
        public void LoginDataLength()
        {
            this.UIMap.InputUserName();
            this.UIMap.UserIdInputLength();
            this.UIMap.AssetUserIdMaxLength();
            this.UIMap.InputPasswordLength();
            this.UIMap.ClickCancelLogin();

            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        }
        #region Additional test attributes

        // You can use the following additional attributes as you write your tests:

        ////Use TestInitialize to run code before running each test 
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        //}

        ////Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{        
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //    // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        //}

        #endregion

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        private TestContext testContextInstance;

        public UIMap UIMap
        {
            get
            {
                if ((this.map == null))
                {
                    this.map = new UIMap();
                }

                return this.map;
            }
        }

        private UIMap map;
    }
}
